<template>
    <div>
        <mt-header class="plain" fixed>
            <mt-button icon="back" slot="left" @click="goBack">返回</mt-button>
            <mt-button slot="right" @click="goBack">取消</mt-button>
        </mt-header>

        <div class="info-container">
            <div class="info-list">
                <div class="info-item text-left">
                    <div class="item-cover " v-if="data.introimageurl" :style="{height: imgHeight}">
                        <img :src="data.introimageurl" alt="">
                    </div>
                    <div class="item-title color-default">
                        <span class="text">{{data.name}}</span>
                        <span class="img" v-for="(x, index) in '01234'" :key="index" v-if="index < (data.rating || 0)">
                            <img :src="img.star">
                        </span>
                    </div>
                    <div class="item-desc-content color-dark">
                        <div v-html="data.description"></div>
                    </div>
                </div>
            </div>
        </div>
        <div class="info-button bg-default" @click="chooseSchool()">报考该学校</div>
    </div>
</template>

<script>

import starImg from '@/assets/images/personal/学校星级.png'
import { Toast } from 'mint-ui'
import { Const } from '@/consts'
import schoolApi from '@/api/school'

import utils from '@/utils'

export default {
    data() {
        return {
            img: {
                star: starImg
            },
            
            schoolId: '',
            courseId: '',
            data: {}
        }
    },

    created() {
        this.schoolId = this.$route.query.schoolId
        this.courseId = this.$route.query.courseId || (utils.get('USER_COURSE') || {}).courseid
        this.getDetail()
    },

    methods: {
        goBack() {
            this.$router.replace('/personal/school/list');
        },

        getDetail() {
            schoolApi.getSchoolInfo({
                params: {
                    schoolid: this.schoolId
                }
            }).then(resp => {
                this.data = resp[Const.RESP_RESULT] || {}
            }).catch(resp => {
                if (resp.statusCode == '200') {
                    Toast(resp[Const.RESP_MESSAGE] || '获取信息失败');
                }
            })
        },

        chooseSchool() {
            schoolApi.joinSchool({
                params: {
                    schoolid: this.schoolId,
                    courseid: this.courseId
                }
            }).then(resp => {
                Toast(resp[Const.RESP_MESSAGE])
                this.$router.replace('/personal');
            }).catch(resp => {
                if (resp.statusCode == '200') {
                    Toast(resp[Const.RESP_MESSAGE] || '出错了 ...');
                }
            })
        }
    }
}
</script>

<style lang="scss" scoped>
$offset-x: 16px;
$scale: 1.2;
.info-container {
    margin-left: $offset-x;
    margin-right: $offset-x;
    margin-top: 55px;
    margin-bottom: 80px;

    .option-list {
        padding-top: 8px;
        border-top: 1px solid #dddddd;
        
        .option-item {
            height: 48px;
            border-bottom: 1px solid #dddddd;
            font-size: 16px * $scale;
            text-align: left;
            color: #000000;
        }
    }

    .info-list {
        .info-item {
            border-bottom: 1px solid #dddddd;
            padding: 16px 0 18px 0;

            &:last-child {
                border-bottom: none;
            }

            .item-cover {
                width: 100%;
                overflow: hidden;
                border-radius: 5px;
                
                img {
                    width: 100%;
                }
            }

            .item-title {
                font-size: 14px * $scale;
                margin: 18px 0 16px 0;

                .text {
                    margin-right: 9px;
                }

                .img {
                    
                    margin-left: 3px;
                    
                    img {
                        width: 12px;
                        height: 12px;
                    }
                }
            }

            .item-desc-title {
                font-size: 14px * $scale;
                margin-bottom: 9px;
            }

            .item-desc-content {
                font-size: 12px * $scale;
                line-height: 18px;
            }
        }
    }

}

.info-button {
    $height: 55px;
    position: fixed;
    bottom: 0;
    height: $height;
    width: 100%;
    color: #ffffff;
    font-size: 18px;
    line-height: $height;
}
</style>
